<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class jQuickForm_Group_Accordion extends HTML_QuickForm2_Container_Group {
    public $accordion_current = false;
    public function render(HTML_QuickForm2_Renderer $renderer){
//        $renderer = new HTML_QuickForm2_Renderer_Default();
        jQuickForm::css()->addCssInline('
        .jqf_accordion_wrap{
            margin-bottom:10px;
        }
        .jqf_accordion{
            border:1px solid #AAAAAA;
            font-size:20px;
            cursor:pointer;
            margin:0;
            color:#AAAAAA;
            padding:3px 10px;
            background:#F2F2F2;
            -moz-border-radius:10px;
        }
        .jqf_accordion_row{
            -moz-border-radius:0 0 10px 10px;
            border:1px solid #AAAAAA;
            padding:10px;
        }
        .jqf_accordion_dn{
            display:none;
            margin-bottom:5px;
        }
        .jqf_accordion_opened {
            -moz-border-radius:10px 10px 0 0;
            border:1px solid #AAAAAA;
            border-bottom:0;
        }
        ','jqf_accordion');
        jQuickForm::js()->addJsOnload('
        jQuery(".jqf_accordion").click(function(){
            jQuery("h2.jqf_accordion[rel="+jQuery(this).attr("rel")+"]").removeClass("jqf_accordion_opened");
            jQuery(this).addClass("jqf_accordion_opened");
            jQuery("div.jqf_accordion_row[rel="+jQuery(this).attr("rel")+"]").addClass("jqf_accordion_dn");
            jQuery(this).next().removeClass("jqf_accordion_dn");
        });
        ','jqf_accordion_dn');
        $renderer->setTemplateForId($this->getId(),'
        <div class="jqf_accordion_wrap">
            <h2 class="jqf_accordion'.($this->accordion_current?' jqf_accordion_opened':'').'" rel="'.$this->getContainer()->getId().'">{label}</h2>
            <div class="jqf_accordion_row'.(!$this->accordion_current?' jqf_accordion_dn':'').'" rel="'.$this->getContainer()->getId().'">
            {content}
            </div>
        </div>
        ');

        $form = $this->getForm();
        jQuickForm::js()->addJsOnload('
        jQuery("input[type=submit]").click(function(){
            jQuery("h2.jqf_accordion").addClass("jqf_accordion_opened");
            jQuery("div.jqf_accordion_row").removeClass("jqf_accordion_dn");
            return true;
        });
        ');

        return parent::render($renderer);
    }

}
?>